import requests

from api.ihrm_login_api import IhrmApi

token = "Bearer " + IhrmApi.login({"mobile": "13800000002", "password": "123456"}).json().get('data')

#员工管理模块的接口对象层
class IhrmEmpCURD(object):
    #添加员工
    @classmethod
    def add_emp(cls,json_data):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        header = {"Content-Type":"application/json","Authorization":token}
        resp = requests.post(url=url, headers=header, json=json_data)
        return resp

    #查询员工
    @classmethod
    def query_emp(cls,emp_id):
        url = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        header = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.get(url=url,headers=header)
        return resp

    #修改员工
    @classmethod
    def modify_emp(cls,emp_id,modify_data):
        url = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        header = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.put(url=url, headers=header,json=modify_data)
        return resp
    #删除员工
    @classmethod
    def delete_emp(cls,emp_id):
        url = "http://ihrm-test.itheima.net/api/sys/user/" + emp_id
        header = {"Content-Type": "application/json", "Authorization": token}
        resp = requests.delete(url=url, headers=header)
        return resp

if __name__ == '__main__':
    # resp_add = IhrmEmpCURD.add_emp({"username":"吃饭睡觉","mobile":"13902832863","workNumber":"243252"})
    # print(resp_add.json())
    resp_query = IhrmEmpCURD.query_emp("1469576290322350080")
    print(resp_query.json())
